package com.boodaba.todocarts.test.app;
import java.util.ArrayList;
import java.util.List;

import org.jmock.Expectations;
import org.junit.runner.RunWith;

import com.boodaba.todocarts.app.ILabelActivity;
import com.boodaba.todocarts.app.LabelPresenter;
import com.boodaba.todocarts.domain.ILabelRepository;
import com.boodaba.todocarts.domain.Label;

import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import com.googlecode.instinct.marker.annotate.BeforeSpecification;
import com.googlecode.instinct.marker.annotate.Mock;
import com.googlecode.instinct.marker.annotate.Specification;
import com.googlecode.instinct.marker.annotate.Subject;


@RunWith(InstinctRunner.class)
public class LabelPresenterSpecs {
	@Subject private LabelPresenter SUT;
	
	@Mock private ILabelActivity labelActivity;
	@Mock private ILabelRepository labelRepository;
	
	@BeforeSpecification
	public void setUp() {
		SUT = new LabelPresenter(labelRepository);
	}
	
	@Specification
	void shouldSetTitleListOnActivity() {
		expect.that(new Expectations() {
			{
				List<Label> labelList = new ArrayList<Label>();
				labelList.add(new Label("label 1"));
				labelList.add(new Label("label 2"));
				labelList.add(new Label("label 3"));
				oneOf(labelRepository).findAll(); will(returnValue(labelList));
				
				List<String> titleList = new ArrayList<String>();
				titleList.add("label 1");
				titleList.add("label 2");
				titleList.add("label 3");
				oneOf(labelActivity).setLabelList(titleList);
			}
		});
		SUT.initializeWith(labelActivity);
	}
	
	@Specification
	void shouldSetTitleListOnReActivity() {
		expect.that(new Expectations() {
			{
				oneOf(labelRepository).findAll(); will(returnValue(new ArrayList<Label>()));
				oneOf(labelActivity).setLabelList(new ArrayList<String>());
				
				List<Label> labelList = new ArrayList<Label>();
				labelList.add(new Label("label 1"));
				labelList.add(new Label("label 2"));
				labelList.add(new Label("label 3"));
				oneOf(labelRepository).findAll(); will(returnValue(labelList));
				
				List<String> titleList = new ArrayList<String>();
				titleList.add("label 1");
				titleList.add("label 2");
				titleList.add("label 3");
				oneOf(labelActivity).setLabelList(titleList);
			}
		});
		SUT.initializeWith(labelActivity);
		SUT.returnTo();
	}
	
	@Specification
	void shouldStartCreateLabelActivity() {
		expect.that(new Expectations() {{
			oneOf(labelRepository).findAll(); will(returnValue(new ArrayList<Label>()));
			oneOf(labelActivity).setLabelList(new ArrayList<String>());
			
			oneOf(labelActivity).startAddLabel();
		}});
		SUT.initializeWith(labelActivity);
		SUT.startAddLabel();
	}
	
	@Specification
	void shouldStartEditLabelActivity() {
		expect.that(new Expectations() {{
			oneOf(labelRepository).findAll(); will(returnValue(new ArrayList<Label>()));
			oneOf(labelActivity).setLabelList(new ArrayList<String>());
			
			oneOf(labelActivity).getSelectedTitle(); will(returnValue("label 1"));
			oneOf(labelActivity).startEditLabel("label 1");
		}});
		SUT.initializeWith(labelActivity);
		SUT.startEditLabel();
	}
	
	@Specification
	void shouldShowLabelTodosActivity() {
		expect.that(new Expectations() {{
			oneOf(labelRepository).findAll(); will(returnValue(new ArrayList<Label>()));
			oneOf(labelActivity).setLabelList(new ArrayList<String>());
			
			oneOf(labelActivity).getSelectedTitle(); will(returnValue("label 1"));
			oneOf(labelActivity).startLabelTodos("label 1");
		}});
		SUT.initializeWith(labelActivity);
		SUT.showLabelTodos();
	}
}
